/**
 * This is a Universal Logger Class
 * It is used for logging all classes
 * @author Harsha Narayan
 * @author Vaarnan Drolia
 */
package core;

import java.util.logging.Level;
import java.util.logging.FileHandler;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public class Log
{
	private static Logger logger = Logger.getLogger(Log.class.getName());


	/**
	 * initialize logger
	 */
	public static void init() {
		try {
			LogManager lm = LogManager.getLogManager();
			FileHandler fh = new FileHandler("log_test.xml");

			lm.addLogger(logger);

			logger.addHandler(fh);
		}
		catch (Exception e) {
			System.out.println("Exception thrown: " + e);
			e.printStackTrace();
		}
	}

	/**
	 * prints the debugMessage to log
	 * @param debugMessage
	 */
	public static void debug(String debugMessage) {
		logger.log(Level.INFO, debugMessage);
	}

//	public void enter(String s) {
//		try {
//			br.write(s + NEW_LINE);
//		} catch (IOException e) {
//			error(e.getMessage());
//		}
//	}
//
//	public void exit(String s) {
//		try {
//			br.write(s + NEW_LINE);
//		} catch (IOException e) {
//			error(e.getMessage());
//		}
//	}

	/**
	 * logs the warnMessage
	 * @param warnMessage
	 */
	public static void warn(String warnMessage) {
		logger.log(Level.WARNING,warnMessage);
	}

	/**
	 * logs the errorMessage
	 * @param errorMessage
	 */
	public static void error(String errorMessage) {
		logger.log(Level.SEVERE, errorMessage);
	}

	/**
	 * sets the level of the logger, by java logger conventions
	 * @param newLevel
	 */
	public static void setLogLevel(Level newLevel) {
		logger.setLevel(newLevel);
	}
}